package ic.distribution.controller;

import IC.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import ic.distribution.domain.DTO.CountDTO;
import ic.distribution.domain.DTO.DefenseDTO;
import ic.distribution.domain.DTO.VehicleDTO;
import ic.distribution.domain.PO.DefensePO;
import ic.distribution.domain.Vehicle;
import ic.distribution.service.VehicledeploymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestController
@RequestMapping("/vehicledeployment")
public class VehicledeploymentController {

    @Autowired
    private VehicledeploymentService vehicledeploymentService;

    @PostMapping("/carlist")
    public R get(@RequestBody VehicleDTO vehicleDTO) {
        PageInfo<Vehicle> findlist = vehicledeploymentService.searchVehicleDeploymentTasks(vehicleDTO);
        return R.ok(findlist);
    }
    /**
     * 新增布控
     */
    @PostMapping("/add")
    public R add(@RequestBody Vehicle vehicle)
    {
        vehicledeploymentService.add(vehicle);
        return R.ok();
    }
    /**
     * 撤销布控
     */
    @GetMapping("/updstatu/{id}")
    public R updstatu(@PathVariable Integer id)
    {
        vehicledeploymentService.updstatu(id);
        return R.ok();
    }

    /**
     * 修改布控
     */
    @PostMapping("/update")
    public R update(@RequestBody Vehicle vehicle)
    {
        vehicledeploymentService.update(vehicle);
        return R.ok();
    }

    @GetMapping("findVehicledeploymentCount")
    public R findVehicledeploymentCount(){
        List<CountDTO> countDTOS=vehicledeploymentService.findVehicledeploymentCount();
        return R.ok(countDTOS);
    }


    /**
     * author 邹广烨
     * */
    @PostMapping("/updstatu/{id}")
    public R updcarstatu(@PathVariable Integer id){
       vehicledeploymentService.updcarstatu(id);
        return null;
    }


    /**
     * author 邹广烨
     * */
//    @PostMapping("/updstatu/{id}")
//    public R updcarstatu(@PathVariable Integer id){
//       vehicledeploymentService.updstatu(id);
//        return null;
//    }
    public static void main(String[] args) {
        String sampleText1 = "李骏强19512425283";
        String sampleText2 = "李聪-18668630875";
        String sampleText3 = "包乐天1+123456789101";
        String sampleText4 = "无效文本";

        extractAndPrintPhoneNumber(sampleText1); // 输出: 19512425283
        extractAndPrintPhoneNumber(sampleText2); // 输出: 18668630875
        extractAndPrintPhoneNumber(sampleText3); // 输出: 123456789101
        extractAndPrintPhoneNumber(sampleText4); // 不输出
    }

    /**
     * 从给定的文本中提取手机号码，并打印出来。如果不是有效的手机号格式，则不打印。
     *
     * @param text 要从中提取手机号码的文本。
     */


    public static void extractAndPrintPhoneNumber(String text) {
        // 定义一个正则表达式，用于匹配11位数字的手机号码。
        String regex = "\\b(\\d{11})\\b";

        // 编译正则表达式。
        Pattern pattern = Pattern.compile(regex);

        // 创建匹配器以在输入文本中查找匹配项。
        Matcher matcher = pattern.matcher(text);

        // 如果找到匹配项，则打印手机号码。
        if (matcher.find()) {
            System.out.println(matcher.group(1)); // 打印第一个捕获组，即手机号码。
        }
        // 如果不是有效的手机号格式，则不打印任何内容。
    }

}
